package com.indusfo.spc.controller;

import com.indusfo.spc.exception.GlobalException;
import com.indusfo.spc.service.RoleRightService;
import com.indusfo.spc.vo.JSONObject;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *角色权限
 * @author 贺闻博
 * 
 *   2018年11月30日
 */
@Controller
@RequestMapping("RoleRight")
public class RoleRightContrllor {
    @Autowired
    private RoleRightService RoleRight;

    /**
     * 查询角色权限接口
     * @param roleRight
     * @return
     */
    @RequestMapping(value="selectRoleRights")
    @ResponseBody
    public JSONObject selectRoleRights(com.indusfo.spc.pojo.RoleRight roleRight){
          JSONObject ListroleRight =RoleRight.selectRoleRight(roleRight);
          return ListroleRight;
    }
    /**
     * 新增和更新角色权限
     * @param roleRight
     * @return
     */
    @RequestMapping(value="updateRoleRights")
    @ResponseBody
    public JSONObject updateRoleRights(com.indusfo.spc.pojo.RoleRight roleRight){
          JSONObject ListroleRight =RoleRight.updateRoleRight(roleRight);
          return ListroleRight;
    }

    /**
     * 启用和停用角色权限信息
     * @param lRoleRightId
     * @param lDataState
     * @return
     */
    @RequestMapping(value="deleteRoleRights")
    @ResponseBody
    public JSONObject deleteRoleRights(Long[] lRoleRightId, Integer lDataState){
        String msg = "";
        try {
            msg =RoleRight.deleteRoleRight(lRoleRightId, lDataState);
        } catch (GlobalException e) {
            e.printStackTrace();
            return JSONObject.build(401, e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return JSONObject.build(401, "服务器未知异常");
        }
        return JSONObject.oK(msg);
    }
    /**
     * 将角色下的角色权限信息删除
     * @Title: RoleRightContrllor
     * @param lRoleId
     * @return
     */
    @RequestMapping(value="deleteRights")
    @ResponseBody
    public JSONObject deleteRights(@Param("lRoleId") Integer lRoleId){
          JSONObject ListroleRight =RoleRight.deleteRight(lRoleId);
          return ListroleRight;
    }

}
